const baseUrl = 'https://api.it120.cc/small4';
let httpTimes = 0;
// 判断 ajax 的请求次数 如果全都请求完了 再 隐藏我们的loading弹框
const request = (params) => {
  wx.showLoading({
    title: '加载中',
  });
  httpTimes++;
  return new Promise((resolve, reject) => {
    wx.request({
      ...params,
      url: baseUrl + params.url,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      },
      complete: () => {
        httpTimes--;
        if (httpTimes === 0) {
          wx.hideLoading();
        }
      },
    });
  });
};

export default request;
